#include "Boss3ItemEntity.h"
Boss3ItemEntity::Boss3ItemEntity(ItemType Itemtype)
{
	_data = new BossItemData(_ID_MAP_STAGE3_BOSS_ITEM_1, Itemtype);
	_range = MOVING_RANGE_X;
	_nextX = _x0 = _data->getRect()->X;
	_v0 = _data->getRect()->Vx;
	_y0 = _data->getRect()->Y;
	life = 5;
}

void Boss3ItemEntity::update(long time){
	//Update state
	if(_data->isDead)
	{
		return;
	}

	//moving update
	_nextX  += _data->getRect()->Vx;
	if((_nextX >= _x0 + _range - _data->getRect()->Width/2) || (_nextX <= _x0 - _range + _data->getRect()->Width/2))
	{
		if(_data->getRect()->Vy == 0 )
		{
			if(_data->getRect()->Y == _y0)
			{
				_data->getRect()->Vy = GRAVITY/10;
				_data->getRect()->Vx = 0;
				_x0 = _data->getRect()->X;
			}
			else
			{
				_data->getRect()->Vx *= -1;
			}
		}
	}
	_data->getRect()->X += _data->getRect()->Vx;
	_data->getRect()->Y += _data->getRect()->Vy;
	_data->sprites->updateCurrent();
}

void Boss3ItemEntity::draw(long time){
	if(_data->isDead)
	{
		return;
	}
	_data->sprites->draw();
}

AbstractData* Boss3ItemEntity::getAbstractData()
{
	return _data;
}

void Boss3ItemEntity::updateData(int actions, int effect)
{
	if(actions == ACTIONS_BOSS3_ITEM_IN_LAND)
	{
		_data->getRect()->Vy = 0;
		_data->getRect()->Vx = -_v0;
	}
	if (actions == ACTIONS_IS_HURT) {
		life -= effect;
		if (life <= 0 && !_data->isDead) {
			_data->isDead = true;
			_data->canInteract = false;
			EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Object_Fire, _data->getRect()->X, _data->getRect()->Y);

		}
	}
}